package com.igeek.shop.service.admin;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.igeek.shop.dao.BaseDao;
import com.igeek.shop.entity.Product;

public class AdminProductServiceImpl implements AdminProductService {
	private BaseDao<Product> dao = new BaseDao<Product>();
	@Override
	public List<Product> queryProduct() {
		String sql = "select * from product";
		Object [] params = {};
		Object list = dao.getList(sql, params, new Product());
		List<Product> productList = (List<Product>) list;
		return productList;
	}

	@Override
	public void addProduct(Product product) {
		String sql = "insert into product (pid,pname,market_price,shop_price,pimage,pdate,is_hot,pdesc,pflag,cid)values(?,?,?,?,?,?,?,?,?,?)";
		Object [] params = {product.getPid(),product.getPname(),product.getMarket_price(),product.getShop_price(),product.getPimage(),product.getPdate(),product.getIs_hot(),product.getPdesc(),product.getPflag(),product.getCid()};
		dao.update(sql, params);
		
	}

	@Override
	public void updateProduct(Product product) {
		String sql = "update product set pname = ?,market_price=?,shop_price=?,pimage=?,pdate=?,is_hot=?,pdesc=?,pflag=?,cid=? where pid = ?";
		Object [] params = {product.getPname(),product.getMarket_price(),product.getShop_price(),product.getPimage(),product.getPdate(),product.getIs_hot(),product.getPdesc(),product.getPflag(),product.getCid(),product.getPid()};
		dao.update(sql, params);
	}

	@Override
	public void deleteProduct(Product product) {
		String sql = "delete from product where pid = ?";
		Object [] params = {product.getPid()};
		dao.update(sql, params);
	}
	@Override
	public Product getProductById(String pid) {
		String sql = "select * from product where pid = ?";
		Object [] params = {pid};
		Product product =(Product) dao.getByOne(sql, params, new Product());		
		return product;
	}

}
